/**
 * <p>Project: patac_k226_git</p>
 * <p>Package: com.patac.hmi.aop.aspect.view</p>
 * <p>File: BaseLogAspect.java</p>
 * <p>Date: 2017/2/28/19:01.</p>
 */
package com.pactera.asmp.server.common.logprint.aspect;


import com.pactera.asmp.server.common.constants.MagicNumberConstant;
import com.pactera.asmp.server.common.logprint.bean.LogBean;
import com.pactera.asmp.server.common.logprint.utils.LogQueue;
import com.pactera.asmp.server.common.logprint.utils.MathUtil;
import com.pactera.asmp.server.common.logprint.utils.StringUtils;
import com.pactera.asmp.server.controller.IndexController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BaseLogAspect {
    public static final Logger logger = LoggerFactory
            .getLogger(IndexController.class);
    private String split = "app:id/";

    /**
     * Add log queue.
     *
     * @param className  the class name
     * @param methodName the method name
     * @param tag        the tag
     * @param args       the args
     */
    protected void addLogQueue(String className, String methodName, String tag, Object... args) {
        LogBean logBean = new LogBean(System.currentTimeMillis(), className, methodName, tag, args);
        LogQueue.getInstance().printLog(logBean);
    }

    /**
     * widget id
     * @param param
     * @return
     */
    private String getWidgetId(String param) {
        try {
            String[] widget = param.split(split);
            if (widget.length > MagicNumberConstant.ONE) {
                String widgetN =  widget[MagicNumberConstant.ONE];
                String widgetId = widgetN.substring(MagicNumberConstant.ZERO, widgetN.length() - MagicNumberConstant.ONE);
                return widgetId;
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        } finally {

        }

        return StringUtils.EMPTY;
    }
    /**
     * widget name
     * @param param
     * @return
     */
    private String getWidgetName(String param) {
        try {
            String viewClass = param.split("\\{")[MagicNumberConstant.ZERO];
            String[] item = viewClass.split("\\.");
            int len = item.length;
            String widgetName = item[MathUtil.safeSubtract(len, MagicNumberConstant.ONE)];
            return widgetName;
        } catch (NullPointerException e) {
            e.printStackTrace();
        } finally {

        }
        return StringUtils.EMPTY;
    }
}
